package subject_set.lanqiao.moli;

import java.util.Scanner;

/**
 * @author haomin
 * @date 2022/11/06 09:47
 **/
public class Num8 {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        while(s.hasNextLine()){
            int count = Integer.parseInt(s.nextLine());
            int ans = 0;
            int preTime = 0, prePro = 0;
            int curTime = 0, curPro = 0;
            for(int i = 0; i < count; ++i){
                String[]  str = s.nextLine().split(" ");
                curTime = Integer.parseInt(str[0].substring(0,2)) * (60 * 60) + Integer.parseInt(str[0].substring(3,5)) * 60 + Integer.parseInt(str[0].substring(6,8));
                curPro = Integer.parseInt(str[1]) * Integer.parseInt(str[2]);

                ans += (curTime - preTime) * prePro;

                preTime = curTime;
                prePro = curPro;
            }
            System.out.println(ans);
        }
    }
}